import config from "@/config"
import http from "@/utils/request"

// 微信公众号
export default {
  //文章
  getArtcleList: {
    url: `${config.API_URL}/article/list`,
    name: "获取微信公众号文章列表",
    get: function (param) {
      return new Promise((resolve, reject) => {
        http.get(this.url, param).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  addArtcle: {
    url: `${config.API_URL}/article/add`,
    name: "添加公众号文章",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  updateArtcle: {
    url: `${config.API_URL}/article/update`,
    name: "修改公众号文章",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  deleteArtcle: {
    url: `${config.API_URL}/article/delete`,
    name: "删除公众号文章",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  publishArtcle: {
    url: `${config.API_URL}/article/publish`,
    name: "发布公众号文章",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getArticleStatus: {
    url: `${config.API_URL}/article/getArticleStatus`,
    name: "获取公众号文章状态",
    get: function (data) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getArticleDetail: {
    url: `${config.API_URL}/article/getOne`,
    name: "获取公众号文章详情",
    get: function (data) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  uploadImg: {
    url: `${config.API_URL}/article/upload`,
    name: "上传图片到公众号",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  // 自定义菜单
  getMenuList: {
    url: `${config.API_URL}/wechatMenu/list`,
    name: "获取自定义菜单列表",
    get: function (data) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
  addMenu: {
    url: `${config.API_URL}/wechatMenu/add`,
    name: "添加自定义菜单",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
  deleteMenu: {
    url: `${config.API_URL}/wechatMenu/delete`,
    name: "删除菜单",
    get: function (data) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
  deleteWeChatMenu: {
    url: `${config.API_URL}/wechatMenu/deleteWechatMenu`,
    name: "删除公众号上的菜单",
    get: function (data) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
  addWeChatMenu: {
    url: `${config.API_URL}/wechatMenu/addWechatMenu`,
    name: "发布自定义菜单",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
}